package com.niit.hbase;

import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.mapreduce.TableMapper;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * Date:2024/11/22
 * Author：Ys
 * Description:
 */                                         // KEYOUT    VALUEOUT
public class WordCountMapper extends TableMapper<Text, IntWritable> {


    @Override
    protected void map(ImmutableBytesWritable key, Result value, Mapper<ImmutableBytesWritable, Result, Text, IntWritable>.Context context) throws IOException, InterruptedException {

        //1.获取一行数据，由于是获取HBase中的数据，所以是二进制的，需要转换为字符串  根据列族和列族获取数据   手机品牌和类型 OPPO FindX
        String data = Bytes.toString(  value.getValue( Bytes.toBytes("C1"), Bytes.toBytes("receiver_phone_type")  )   );
        String[] words = data.split("\\s");// \\s表示一切带有空格的东西  \t 表示空格和换行

        for (String word : words){
            context.write( new Text(word),new IntWritable(1) );
        }



    }
}
